﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Profile;

namespace SocialCee.Authorization
{
    /// <summary>
    /// TODO
    /// Validation
    /// </summary>
    public class ProfileManager
    {
        /// <summary>
        /// Create user profile
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static ProfileBase Create(string userName)
        {
            ProfileBase profile = System.Web.Profile.DefaultProfile.Create(userName, true);
            return profile;
        }

        /// <summary>
        /// Create user profile - commit
        /// </summary>
        /// <param name="profile"></param>
        public static void Save(ProfileBase profile)
        {
            profile.Save();
        }

        /// <summary>
        /// Add user profile property
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="profile"></param>
        /// <param name="proprtyName"></param>
        /// <param name="value"></param>
        public static void AddProperty<T>(ProfileBase profile, string proprtyName, T value)
        {
            profile.SetPropertyValue(proprtyName, value);
            profile.Save();
        }

        /// <summary>
        /// Get profile property
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="profile"></param>
        /// <param name="proprtyName"></param>
        /// <returns></returns>
        public static T GetProperty<T>(ProfileBase profile, string proprtyName)
        {
            return (T) profile.GetPropertyValue(proprtyName);
        }
    }
}
